//
//  HelpView.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/9.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "HelpView.h"

@implementation HelpView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.alpha = 0;
        UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        bgView.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.75];
        [self addSubview:bgView];
        //搭建控件
        [self setUpViews];
    }return self;
}

- (void)setUpViews{
    //白色背景
    UIView * whiteBGView = [[UIView alloc] init];
    whiteBGView.backgroundColor = [UIColor whiteColor];
    whiteBGView.layer.cornerRadius = 6;
    whiteBGView.layer.masksToBounds = YES;
    [self addSubview:whiteBGView];
    //标题
    UILabel * titleLab = [[UILabel alloc] init];
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.text = @"帮助";
    titleLab.textColor = [UIColor blackColor];
    titleLab.font = DEF_FontSize_18;
    [whiteBGView addSubview:titleLab];
    //内容
    UILabel * contentLab = [[UILabel alloc] init];
    contentLab.textAlignment = NSTextAlignmentLeft;
    contentLab.text = @"博帮互助平台接收全体会员监督，但为了不影响受助会员的日常生活，平台在公示内容中隐去了会员的联系方式和住址，若需要了解更多或对公示有异议可通过热线400-888-8888与博帮互助平台取得联系，博帮互助平台将协助会员了解相关情况。";
    contentLab.numberOfLines = 0;
    contentLab.lineBreakMode = 0;
    contentLab.textColor = getColor(@"cecece");
    contentLab.font = DEF_FontSize_12;
    [whiteBGView addSubview:contentLab];
    //分割线
    UIView * lineView = [[UIView alloc] init];
    lineView.backgroundColor = getColor(@"f7f7f7");
    [whiteBGView addSubview:lineView];
    //消除内容按钮
    UIButton * knownBtn = [[UIButton alloc] init];
    [knownBtn setTitle:@"知道了" forState:UIControlStateNormal];
    [knownBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [knownBtn addTarget:self action:@selector(knownBtnClick) forControlEvents:UIControlEventTouchUpInside];
    knownBtn.titleLabel.font = DEF_FontSize_18;
    [whiteBGView addSubview:knownBtn];
    //masonry
    __weak typeof (self)weakSelf = self;
    [whiteBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mas_left).mas_offset(29/WIDTH_6_SCALE);
        make.right.equalTo(weakSelf.mas_right).mas_offset(-29/WIDTH_6_SCALE);
        make.center.equalTo(weakSelf).centerOffset(CGPointMake(0, -100/WIDTH_6_SCALE));
//        make.height.mas_offset(205/WIDTH_6_SCALE);
        make.bottom.equalTo(knownBtn.mas_bottom);
    }];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(whiteBGView);
        make.height.mas_offset(58/WIDTH_6_SCALE);
    }];
    [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLab.mas_bottom).mas_offset(2/WIDTH_6_SCALE);
        make.left.equalTo(whiteBGView.mas_left).mas_offset(16/WIDTH_6_SCALE);
        make.right.equalTo(whiteBGView.mas_right).mas_offset(-16/WIDTH_6_SCALE);
        make.bottom.equalTo(lineView.mas_top).mas_offset(-21/WIDTH_6_SCALE);
    }];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(whiteBGView);
        make.top.equalTo(contentLab.mas_bottom).mas_offset(21/WIDTH_6_SCALE);
        make.height.mas_offset(1/WIDTH_6_SCALE);
    }];
    [knownBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(whiteBGView);
        make.height.mas_offset(45/WIDTH_6_SCALE);
        make.top.equalTo(lineView.mas_bottom);
    }];
}
- (void)show{
    [[UIApplication sharedApplication].delegate.window addSubview:self];
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 1;
    }];
}
- (void)knownBtnClick{
    [[UIApplication sharedApplication].delegate.window addSubview:self];
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
@end
